package com.david.concurrent.threadlocal;

/**
 * @author wade
 * @version 1.0
 * @date 2021/7/29 17:24
 */
public class ThreadLocalTest {

    static ThreadLocal<String> threadLocal = new ThreadLocal<>();

    static void print(String str){
        System.out.println(str+":"+threadLocal.get());
        threadLocal.remove();
    }

  public static void main(String[] args) {
    Thread t1 = new Thread(() -> {
      threadLocal.set("t1 local variable!");
      print("t1");
      System.out.println("t1 remove after:"+threadLocal.get());
    });
      Thread t2 = new Thread(() -> {
          threadLocal.set("t2 local variable!");
          print("t2");
          System.out.println("t2 remove after:"+threadLocal.get());
      });
      t1.start();
      t2.start();
  }
}
